<template>
  <div class="mod-biz.tongtong__lock">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-button v-if="state.hasPermission('tongtong:lock:update')" type="primary" @click="state.updateLockHandle()">更新门锁列表</el-button>
      </el-form-item>
      <!-- <el-form-item>
        <el-button v-if="state.hasPermission('tongtong:lock:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item> -->
      <!-- <el-form-item>
        <el-button v-if="state.hasPermission('tongtong:lock:delete')" type="danger" @click="state.deleteHandle()">删除</el-button>
      </el-form-item> -->
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
              <!-- <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column> -->
              <el-table-column prop="lockAlias" label="锁别名" header-align="center" align="center"></el-table-column>
              <!-- <el-table-column prop="lockId" label="锁id" header-align="center" align="center"></el-table-column> -->
              <el-table-column prop="lockName" label="锁的蓝牙名称" header-align="center" align="center"></el-table-column>
              <el-table-column prop="lockMac" label="锁mac地址" header-align="center" align="center"></el-table-column>
              <el-table-column prop="electricQuantity" label="锁电量" header-align="center" align="center"></el-table-column>
              <!-- <el-table-column prop="featureValue" label="锁特征值，用于表示锁支持的功能" header-align="center" align="center"></el-table-column> -->
              <!-- <el-table-column prop="hasGateway" label="是否有连接网关，1-是、0-否" header-align="center" align="center"></el-table-column>
              <el-table-column prop="lockData" label="锁数据，用于操作锁" header-align="center" align="center"></el-table-column>
              <el-table-column prop="date" label="锁初始化时间" header-align="center" align="center"></el-table-column>
              <el-table-column prop="keyStatus" label="钥匙状态值" header-align="center" align="center"></el-table-column>
              <el-table-column prop="keyId" label="钥匙id" header-align="center" align="center"></el-table-column>
              <el-table-column prop="deletePwd" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="wirelessKeypadFeatureValue" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="keyRight" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="specialValue" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="keyName" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="noKeyPwd" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="passageMode" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="timezoneRawOffset" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="keyboardPwdPersion" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="remoteEnable" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="userType" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="startDate" label="" header-align="center" align="center"></el-table-column>
              <el-table-column prop="endDate" label="" header-align="center" align="center"></el-table-column> -->
              <el-table-column prop="remarks" label="备注" header-align="center" align="center"></el-table-column>
            <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button type="primary" link @click="addUserList(scope.row)">授权用户</el-button>
          <!-- <el-button v-if="state.hasPermission('biz.tongtong:lock:update')" type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button v-if="state.hasPermission('biz.tongtong:lock:delete')" type="primary" link @click="state.deleteHandle(scope.row.id)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <!-- <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update> -->
    <!-- 字典类型数据 -->
    <el-drawer v-if="userDataVisible" v-model="userDataVisible" :title="授权用户" :size="800" :close-on-press-escape="false" class="rr-drawer"> <AddUserList :lockId="state.focusLockId"></AddUserList></el-drawer>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { IObject } from "@/types/interface";
import { reactive, ref, toRefs } from "vue";
//import AddOrUpdate from "./lock-add-or-update.vue";
import AddUserList from "./lockuser.vue";

const userDataVisible = ref(false);
const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/biz/tongtong/lock/page",
  getDataListIsPage: true,
  exportURL: "/biz/tongtong/lock/export",
  deleteURL: "/biz/tongtong/lock",
  updateLockURL: "/biz/tongtong/lock/update",
  focusLockId: ""
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};
const addUserList = (row: IObject) => {
  userDataVisible.value = true;
  state.focusLockId = row.id;
};
</script>
